package com.auto.learning.adapter;

import java.util.ArrayList;

import com.auto.learning.R;
import com.auto.learning.bean.SelectionVo;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class ReadFragmentChapterAdapter extends BaseAdapter {

	private ArrayList<SelectionVo> data = new ArrayList<SelectionVo>();
	private Context context;
	private int type = 1;  //1 中文 2 英文
	
	public ReadFragmentChapterAdapter(Context context,ArrayList<SelectionVo> data,int type){
		this.context = context;
		this.data = data;
		this.type = type;
	}
	
	@Override
	public int getCount() {
		return data.size();
	}

	@Override
	public Object getItem(int position) {
		return data.get(position);
	}

	@Override
	public long getItemId(int position) {
		return data.get(position).getSectionId();
	}

	ViewHolder holder;
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if (convertView == null) {
			convertView = LayoutInflater.from(context).inflate(R.layout.read_chapter_adapter, null);
			holder = new ViewHolder();
			holder.tv_title = (TextView) convertView.findViewById(R.id.tv_title);
			holder.tv_position = (TextView) convertView.findViewById(R.id.tv_position);
			convertView.setTag(holder);
		}else {
			holder = (ViewHolder) convertView.getTag();
		}
		
		if (type == 1) {
			holder.tv_title.setText(data.get(position).getTitle());
		}else if(type == 2){
			holder.tv_title.setText(data.get(position).getTitleEn());
		}
		holder.tv_position.setText((position + 1)+"");
		return convertView;
	}
	
	class ViewHolder{
		TextView tv_title,tv_position;
	}

}
